/**
 * Created by Administrator on 2016/10/31.
 */
angular.module('sortApp', ['ng-sortable'])
    .controller('sortController', ['$scope', function ($scope) {
        $scope.datas= [{name:'数据中心资源',
            item:[
                {text: '数据中心', done: false},
                {text: '机房', done: false},
                {text: '机柜', done: false},
                {text: '带宽', done: false},
                {text: '硬件', done: false},
                {text: '服务器', done: false}
            ],
            title:'datacenter',
            X:'',  //相对于页面的X坐标和Y坐标
            Y:''},
            {name:'IPAM资源',
                item:[
                    {text: 'IP', done: false},
                    {text: '域名', done: false}
                ],
                title:'ipam'},
            {name:'业务资源',
                item:[{text: '业务模块', done: false}
                ],
                title:'firm'},
            {name:'虚拟化资源',
                item:[
                    {text: 'Vcenter', done: false}
                ],
                title:'vm'},
            {name:'云资源',
                item:[
                    {text: '阿里云', done: false},
                    {text: 'AWS', done: false}
                ],
                title:'cloud'},
            {name:'供应商资源',
                item:[
                    {text: '供应商', done: false},
                    {text: '合同', done: false}
                ],
                title:'supplier'}
        ];

        $scope.showResource=true;
        $scope.addItem = function (items) {
            $scope.showResource=false;
            $scope.addItems=items.item;
            $scope.add=function(){
                $scope.addItems.push({text: $scope.itemText, done: false});
                $scope.itemText = '';
                console.log($scope.addItems); // 数据保存到数据库中
            };
        };
        $scope.delete = function (items) {
            var oldItems =items;
            var deleteItem=items.title;
            var newItems= [];
            angular.forEach(oldItems.item, function (item) {
                if (!item.done){
                    newItems.push(item);
                }
            });
            angular.forEach($scope.datas,function(idx){
                if(idx.title==deleteItem){
                    idx.item=newItems;
                }
            })
        };
        $scope.close= function () {
            $scope.showResource=true;
        };

        var Id=document.getElementById('multiply');
        var sortable = Sortable.create(Id,{
            group:'sorting',
            sort:'true'
        });

    }])